package com.sloan.community.util;

import java.io.File;
import org.jaudiotagger.tag.FieldKey;
import org.jaudiotagger.tag.Tag;
import org.jaudiotagger.audio.AudioFile;
import org.jaudiotagger.audio.AudioFileIO;
/**
 * @Author: yaosj
 * @CreateTime: 2024-12-31
 */
public class AudioUtils {
    public static String getLyricsFromMp3(String filePath) {
        try {
            File mp3File = new File(filePath);
            AudioFile audioFile = AudioFileIO.read(mp3File);
            Tag tag = audioFile.getTag();
            String lyrics = tag.getFirst(FieldKey.LYRICS);
            return lyrics != null ? lyrics : "No lyrics found";
        } catch (Exception e) {
            e.printStackTrace();
            return "Error retrieving lyrics";
        }
    }

    public static void main(String[] args) {
        String filePath = "C:\\software\\JetBrains\\idea_ws\\community\\src\\main\\resources\\templates\\other\\陈一发儿 - 童话镇.flac";
        String lyrics = getLyricsFromMp3(filePath);
        System.out.println(lyrics);
    }

}
